package com.xiaomaoaixue.wecom.factory;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.NumberUtil;
import com.xiaomaoaixue.common.core.enums.UserStatus;
import com.xiaomaoaixue.common.core.enums.UserType;
import com.xiaomaoaixue.common.core.utils.StringUtils;
import com.xiaomaoaixue.system.api.domain.SysDept;
import com.xiaomaoaixue.system.api.domain.SysUser;
import com.xiaomaoaixue.wecom.domain.callback.WeBackBaseVo;
import com.xiaomaoaixue.wecom.domain.callback.WeBackDeptVo;
import com.xiaomaoaixue.wecom.domain.callback.WeBackUserVo;

import java.util.Date;

/**
 * @author danmo
 * @description 事件类型策略接口
 * @date 2021/1/20 22:00
 **/
public abstract class WeEventStrategy {
    protected final String tag = "tag";
    protected final String tagGroup = "tag_group";

    public abstract void eventHandle(WeBackBaseVo message);

    //生成成员数据
   public SysUser setWeUserData(WeBackUserVo message) {
       SysUser weUser = new SysUser();

       weUser.setUserName(message.getUserID());
       weUser.setEmail(message.getEmail());
       weUser.setNickName(message.getName()) ;

       if(StringUtils.isNotNull(message.getGender())) {
           weUser.setSex(message.getGender() + "");
       }
       //weUser.setaddress(message.getAddress())
       weUser.setPhonenumber(message.getMobile());
       weUser.setAvatar(message.getAvatar());
       // 1=已激活，2=已禁用，4=未激活，5=退出企业。
       if(message.getStatus()!=null) {
           weUser.setStatus(UserStatus.getUserStatusByWeStatus(message.getStatus()).getCode());
       }

       // 直属上级
       if(StringUtils.isNotNull(message.getDirectLeader())) {
           String[] leaders = message.getDirectLeader().split(",");// 可能又多个
           weUser.setDirectLeader(leaders[0]);
       }
       // 部门
       if(StringUtils.isNotNull(message.getDepartment())) {
           String[] depts = message.getDepartment().split(","); // 可能又多个
           weUser.setDeptId(NumberUtil.parseLong(depts[0]));
       }
        // 是否主管
       if(StringUtils.isNotNull(message.getIsLeaderInDept())) {
           String[] isleaders = message.getIsLeaderInDept().split(","); // 可能又多个
           weUser.setIsLeaderInDept(NumberUtil.parseInt(isleaders[0]));
       }

        return weUser;
    }

    //部门信息
    public SysDept setWeDepartMent(WeBackDeptVo message){
        SysDept dept = new SysDept();
        if (message.getId() != null) {
            dept.setDeptId(Long.parseLong(message.getId()));
        }
        if (message.getName() != null) {
            dept.setDeptName(message.getName());
        }
        if (message.getParentId() != null) {
            dept.setParentId(Long.valueOf(message.getParentId()));
        }
        if (message.getOrder() != null) {
            dept.setOrderNum(message.getOrder());
        }
        return dept;
    }
}
